﻿using Plugins.Interfaces;
using Plugins.Threading;

namespace Plugins.Controls
{
    public class PluginWindowWorkItem<T, U> : PluginWorkItem<T>, IPluginWorkItem
        where U : PluginWindow
    {
        private U _window;
        public PluginWindowWorkItem(U window)
        {
            _window = window;
        }
        public U Window { get { return _window; } }
        protected override void Initialize()
        {
            if (_window != null)
            {
                PluginControlHelper.Action<PluginWindow>(_window, control =>
                {
                    control.ToolBarWindowItems.Disable("startButton");
                    control.ToolBarWindowItems.Enable("stopButton");
                    control.ToolBarWindowItems.Disable("resetButton");
                });
                base.Initialize();
            }
        }
        protected override void Terminate()
        {
            if (_window != null)
            {
                base.Terminate();
                PluginControlHelper.Action<PluginWindow>(_window, control =>
                {
                    control.ToolBarWindowItems.Enable("startButton");
                    control.ToolBarWindowItems.Disable("stopButton");
                    control.ToolBarWindowItems.Enable("resetButton");
                });
            }
        }
    }
}
